package com.doit.demo01;

import java.io.*;

public class test04 {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\work\\abc\\IO练习题");
        File dest = new File("D:\\work\\abc\\IO练习题\\第三题\\复制");
        if(!dest.exists())
            dest.mkdirs();
        show(file);
        copy(file,dest);

    }
    private static void copy(File file, File dest) throws IOException {
        if(file.isDirectory()){
            File[] dir = file.listFiles();
            for (File file1 : dir) {
                if (file1.isFile()){
                    boolean b = file1.getName().toLowerCase().endsWith(".java");
                    if (b){
                        InputStream fr = new FileInputStream(file1.getPath());
                        String n = dest.getPath()+"\\"+file1.getName().replace(".java",".jad" ); //文件路径加名字
                        OutputStream fw = new FileOutputStream(n);
                        int len = 0;
                        byte[] bytes = new byte[1024];
                        while ((len=fr.read(bytes))!=-1){
                            fw.write(bytes,0,len);
                            fw.flush();
                        }
                        fw.close();fr.close();
                    }
                }
                else
                    copy(file1,dest);
            }
        }
        else
            copy(file,dest);
    }

    public static void show(File file){
        if(file.isDirectory()){
            File[] dir = file.listFiles();
            for (File file1 : dir) {
                if (file1.isFile()){
                    boolean b = file1.getName().toLowerCase().endsWith(".java");
                    if (b){
                        System.out.println(file1);
                    }
                }
                else
                    show(file1);
            }
        }
        else
            show(file);
    }
}
